<template>
  <el-dialog title="修改密码" :close-on-click-modal="false" :visible.sync="visible">
    <el-form
      size="small"
      :model="dataForm"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="100px"
    >
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="dataForm.password" placeholder="密码"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { treeDataTranslate } from '@/utils'
import Tinymce from '@/components/Tinymce'
import Vue from 'vue'
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        userId: 0,
        password: ''
      }
    }
  },
  components: {
    Tinymce
  },
  methods: {
    init(id) {
      this.dataForm.userId = id || 0
      this.visible = true
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.$http({
            url: `/user/member/${!this.dataForm.userId ? 'save' : 'update'}`,
            method: 'post',
            data: {
              userId: this.dataForm.userId || undefined,
              password: this.dataForm.password
            }
          }).then(data => {
            if (data && data.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.visible = false
              this.$emit('refreshDataList')
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
  }
}
</script>
